import request from "../utils/request";

const jobDev_url = '/flink/jobDev/'

const taskInfo_url = '/flink/taskInfo/'

const work_url = '/flink/jobSubmit/'

const studio_url = '/flink/studio/'

const jobInstance_url = '/flink/jobInstance/'

const functionManage_url = '/document/'

const session_url = '/session/'

const xxlJob_url = '/xxljob/'

export function getTree(params) {
  return request({
    url: '/flink/taskDir/loadTree',
    method: 'get',
    params
  });
}

export function searchTree(params) {
  return request({
    url: '/flink/taskDir/searchTree',
    method: 'get',
    params
  });
}

// check-sql
export function checkSql(data) {
  return request({
    url: jobDev_url + 'checkSql',
    method: 'post',
    data
  })
}

// 执行sql
export function executeSql(data) {
  return request({
    url: jobDev_url + 'excuteSql',
    method: 'post',
    data
  })
}

// 保存作业
export function saveWork(data) {
  return request({
    url: taskInfo_url + 'saveTaskParams',
    method: 'post',
    data
  })
}

// 作业提交
export function submitWork(data) {
  return request({
    url: work_url + 'submit',
    method: 'get',
    params: data
  })
}

// 作业发布
export function releaseWork(data) {
  return request({
    url: work_url + 'release',
    method: 'get',
    params: data
  })
}

// 作业开发
export function developWork(data) {
  return request({
    url: work_url + 'developTask',
    method: 'get',
    params: data
  })
}

// 作业上线
export function onlineWork(data) {
  return request({
    url: work_url + 'onLineTask',
    method: 'get',
    params: data
  })
}

// 作业下线或停止
export function offlineWork(data) {
  return request({
    url: work_url + 'offLineTask',
    method: 'get',
    params: data
  })
}

// 重启作业
export function restartWork(data) {
  return request({
    url: work_url + 'restartTask',
    method: 'get',
    params: data
  })
}

// 根据jobId获取作业的执行情况
export function queryExecuteInfo(data) {
  return request({
    url: studio_url + 'jobInfo',
    method: 'get',
    params: data
  })
}

// 根据集群id获取集群进程信息
export function queryProcessInfo(data) {
  return request({
    url: studio_url + 'listJobs',
    method: 'get',
    params: data
  })
}

// 获取作业执行历史情况
export function queryHistoryInfo(data) {
  return request({
    url: studio_url + 'history',
    method: 'post',
    data
  })
}

// 进程中作业取消
export function cancelProcess(data) {
  return request({
    url: studio_url + 'studio/cancel',
    method: 'get',
    params: data
  })
}

// 进程保存点触发
export function saveProcess(data) {
  return request({
    url: studio_url + 'studio/savepointTrigger',
    method: 'get',
    params: data
  })
}

// 进程保存点停止
export function stopProcess(data) {
  return request({
    url: studio_url + 'studio/savepointStop',
    method: 'get',
    params: data
  })
}

// 进程保存点取消
export function savepointCancel(data) {
  return request({
    url: studio_url + 'studio/savepointCancel',
    method: 'get',
    params: data
  })
}

// 点击数据表生成flinksql
export function generateFlinkSql(data) {
  return request({
    url: jobDev_url + 'getFlinkSql',
    method: 'get',
    params: data
  })
}

// 作业开发参数展示
export function queryTaskParams(data) {
  return request({
    url: taskInfo_url + 'queryTaskParams',
    method: 'get',
    params: data
  })
}

// 根据集群id获取集群进程信息
export function queryListJobs(data) {
  return request({
    url: studio_url + 'listJobs',
    method: 'get',
    params: data
  })
}

// 实时任务作业异常日志查询
export function getJobExceptionLog(data) {
  return request({
    url: jobInstance_url + 'jobExceptionLog',
    method: 'get',
    params: data
  })
}

// 实时任务查看日志接口
export function getJobLogList(data, isHistory) {
  if (isHistory === 'history') {
    return request({
      url: jobInstance_url + 'list?isHistory=true',
      method: 'post',
      data
    })
  } else {
    return request({
      url: jobInstance_url + 'list',
      method: 'post',
      data
    })
  }
}

// 函数管理---分页查询
export function getFunctionPage(data) {
  return request({
    url: functionManage_url + 'page',
    method: 'post',
    data
  })
}

// 添加会话
export function createSession(data) {
  return request({
    url: session_url + 'add',
    method: 'post',
    data
  })
}

// 查询会话列表
export function getSessionPage(data) {
  return request({
    url: session_url + 'list',
    method: 'get',
    params: data
  })
}

// 删除会话
export function deleteSession(data) {
  return request({
    url: session_url + 'clear',
    method: 'get',
    params: data
  })
}

// 查询session的表
export function getSessionTables(data) {
  return request({
    url: session_url + 'showTables',
    method: 'get',
    params: data
  })
}

// 查询表的描述
export function getTableDesc(data) {
  return request({
    url: session_url + 'describeTable',
    method: 'get',
    params: data
  })
}

// 删除session的表
export function deleteTable(data) {
  return request({
    url: session_url + 'deleteTable',
    method: 'get',
    params: data
  })
}

// 周期任务增加调度设置
export function addSchedule(data) {
  return request({
    url: taskInfo_url + 'addSchedule',
    method: 'post',
    data
  })
}

// 周期任务分页查询日志列表
export function getCycle(data) {
  return request({
    url: taskInfo_url + 'log/page',
    method: 'post',
    data
  })
}

// 周期任务日志详情
export function getCycleInfo(data) {
  return request({
    url: taskInfo_url + 'log/logDetailCat',
    method: 'get',
    params: data
  })
}

// 执行一次任务
export function executOnce(data) {
  return request({
    url: xxlJob_url + 'trigger',
    method: 'get',
    params: data
  })
}

// 启动任务
export function startTask(data) {
  return request({
    url: xxlJob_url + 'start',
    method: 'get',
    params: data
  })
}

// 停止任务
export function stopTask(data) {
  return request({
    url: xxlJob_url + 'stop',
    method: 'get',
    params: data
  })
}
